package list_Node;
//142. 环形链表 II
public class Num142_detectCycle {
    public ListNode detectCycle(ListNode head) {
        ListNode fast = head,slow = head;
        while (fast!=null&&fast.next!=null){
            fast = fast.next.next;
            slow = slow.next;
            //此时fast和slow相遇
            if (fast==slow){
                fast=head;
                while (fast!=slow){
                    fast=fast.next;
                    slow=slow.next;

                }
                return slow;


            }

        }
        return null;


    }

}
